package com.grace.common;

import com.grace.model.SysUser;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;

@Slf4j
public class RequestHolder {
    /**
     * 部门模块
     */
    //常量存放池用户对象userHolder
    private static final ThreadLocal<SysUser> userHolder = new ThreadLocal<SysUser>();
    //常量存放requestHolder
    private static final ThreadLocal<HttpServletRequest> requestHolder = new ThreadLocal<HttpServletRequest>();

    /**
     * 用户模块
     *
     * @param user
     */
    //存放用户
    public static void add(SysUser user) {
        userHolder.set(user);
    }

    //存放request
    public static void add(HttpServletRequest request) {
        requestHolder.set(request);
    }

    //获取常量用户池的用户信息
    public static SysUser getCurrentUser() {
        return userHolder.get();
    }

    //获取request的信息
    public static HttpServletRequest getCurrentRequest() {
        return requestHolder.get();
    }

    //移除(清空)进程结束了之后，需要把它从内存中移除
    public static void remove() {
        userHolder.remove();
        requestHolder.remove();
    }
}
